package com.practise.restful.control;

import com.practise.restful.model.XmlUser;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping(value = "/practise")
public class UserController {

    @RequestMapping(value = "/hello",produces = MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE)
    public HashMap<String,String> hello(){
        HashMap<String,String> mp = new HashMap<>();
        mp.put("user","张三");
        mp.put("passwd","1231231");
        return mp;
    }

    @GetMapping(value = "/getuser",produces = MediaType.APPLICATION_XML_VALUE)
    public ResponseEntity<XmlUser> getuser(){
        HashMap<String,String> hsmap = new HashMap<>();
        hsmap.put("name","张三一");
        hsmap.put("age","23");
        return ResponseEntity.status(HttpStatus.CREATED)
                .body(XmlUser.builder().id(123).name("张三").age(28).addr("12323232")
                        .hmap(hsmap).build());
    }
}
